from django.shortcuts import render

from rest_framework.viewsets import ViewSet
from rest_framework.response import Response


from shops.models import ShopsModel
from shops.serializers import ShopsSer
from send.models import SendModel
from send.serializers import SendSer

# Create your views here.

class TerrceView(ViewSet):

    # 获取所有未通过申请的骑手
    def verify_desc(self,request):
        try:
            user = SendModel.objects.filter(is_apply=False)

            ser = SendSer(user,many=True)
            return Response({'errcode':0,'msg':'ok！','data':ser.data})
        except Exception as e:
            print(str(e))
            return Response({'errcode':1,'msg':'服务器错误'})

    # 获取所有未通过申请的商家
    def verify_list(self,request):
        try:

            user = ShopsModel.objects.filter(is_apply=False)

            ser = ShopsSer(user,many=True)

            return Response({"errcode": 0, "msg": "ok！",'data':ser.data})
        except Exception as e:
            print("错误", e)
            return Response({'errcode':3,'msg':'服务器错误'})

    # 同意申请
    def consent(self,request):

        id = request.data.get('id')
        try:
            ShopsModel.objects.filter(id=id).update(is_apply=True)
            return Response({'errcode':0,'msg':'同意申请成功'})

        except Exception as e:
            print(str(e))
            return Response({'errcode':1,'msg':'修改失败'})

